/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Text, LineColumn, InputLine, TextArea, BlobInputList, InputDatalist,} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, useItemInputControl,
} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import { objNestSet} from "../../../common/tool";

interface Props extends InternalItemProps {
    label?: string;
    titles?: any[];
}

//常见模型：{特别的配置 } 第三个字段标识：是否标题也是手工录入的？
export const item宏观检验o = [
    ['安全管', {t: '安全管理情况', },],
    ['本体运', {t: '管道本体及运行情况',},],
    ['安全阀', {t: '安全阀', pr: '安全附件与仪表检查情况', span: 6}],
    ['爆破片', {t: '爆破片装置'}],
    ['阻火器', {t: '阻火器装置'}],
    ['切断阀', {t: '紧急切断阀'}],
    ['压力表', {t: '压力表'}],
    ['测温仪', {t: '测温仪表'}],
    ['电阻值', {t: '电阻值测量', }, ],
    ['壁厚', {t: '壁厚测定', }, false ]
];
export const itemA宏观检验: string[] = ['宏观结果'];
item宏观检验o.forEach(([name, title, initIsp], i: number) => {
    itemA宏观检验.push(name as string);
});
const 检验结果选=['符合要求','基本符合要求','不符合要求'];
// export const 等级评定选=['1级','2级','3级','4级'];
/**年度检查 的附页，
 * */
export const AnnAttachment =
React.forwardRef((
    {children, show, alone = true, redId, nestMd, label, titles}: Props, ref
) => {
    const [getInpFilter] = useMeasureInpFilter(null, itemA宏观检验,);
    const {inp, setInp} = useItemInputControl({ref});
    let oldPrefic='';
    return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                            nestMd={nestMd} alone={alone} label={label!}>
             <Text variant="h5">{label}：</Text>
                { item宏观检验o.map(([name,conf,adddesc]: any, i:number) => {
                    const {t: title, pr: prefix, span}=conf;
                    oldPrefic=prefix? prefix:oldPrefic;             //配置可继承性
                    return (<React.Fragment key={i}>
                        项目{i+1} {oldPrefic} {'>'} {title}：
                        <LineColumn key={i}>
                            {adddesc && <InputLine  label={'检验项目的附加叙述标题'}>
                                   <BlobInputList  value={inp?.[name]?.a ||''}
                                                onListChange={v => objNestSet(name,'a', v||undefined,inp,setInp) } />
                                </InputLine>
                            }
                            <InputLine label={'检验结果'}>
                                <InputDatalist value={(inp?.[name]?.r) || ''} datalist={检验结果选}
                                               onListChange={v => objNestSet(name,'r', v||undefined,inp,setInp) } />
                            </InputLine>
                            <InputLine  label={'备注'}>
                                <BlobInputList  value={inp?.[name]?.m ||''} datalist={['见结果栏']}
                                                onListChange={v => objNestSet(name,'m', v||undefined,inp,setInp) } />
                            </InputLine>
{/*                            <InputLine label={'等级评定'}>
                                <InputDatalist value={(inp?.[name]?.c) || ''} datalist={等级评定选}
                                               onListChange={v => objNestSet(name,'c', v||undefined,inp,setInp) } />
                            </InputLine>*/}
                        </LineColumn>
                    </React.Fragment>);
                })
                }
            <Text variant="h5">说明：</Text>表中检验项目备注无法说明清楚的，可在本栏中进一步将缺陷（问题）情况描述清楚：
            <TextArea  value={inp?.宏观结果 ||''} rows={13}
                       onChange={e => setInp({ ...inp, 宏观结果: e.currentTarget.value||undefined}) } />
    </InspectRecordLayout>;
});

